package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.SearchHistoryService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.CommodityProjectDto;
import com.huilian.iotbox.data.dto.SearchHistoryDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/10/25 下午4:16
 */
@RestController
@RequestMapping("/api/searchHistory")
public class SearchHistoryController extends UserInfoController {
    @Autowired
    private SearchHistoryService searchHistoryService;

    /**
     * 添加搜索字
     */
    @PostMapping("/addSearchHistory")
    public ServerResponse addSearchHistory(@RequestBody SearchHistoryDto searchHistoryDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        searchHistoryDto.setSearchTerm(searchHistoryDto.getKeyword());
        searchHistoryDto.setUserId(userInfo.getId());
        return searchHistoryService.addSearchHistory(searchHistoryDto);
    }
    /**
     * 查询搜索字
     */
    @PostMapping("/findSearchHistoryListByUserId")
    public ServerResponse findSearchHistoryListByUserId(@RequestBody SearchHistoryDto searchHistoryDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        searchHistoryDto.setUserId(userInfo.getId());
        return searchHistoryService.findSearchHistoryListByUserId(searchHistoryDto);
    }
    /**
     * 查询搜索字
     */
    @GetMapping("/delAllSearchHistory")
    public ServerResponse delAllSearchHistory(HttpServletRequest request,Integer funType) {
        SearchHistoryDto searchHistoryDto = new SearchHistoryDto();
        UserInfo userInfo = super.getLoginUserInfo(request);
        searchHistoryDto.setUserId(userInfo.getId());
        searchHistoryDto.setFunType(funType);
        return searchHistoryService.delAllSearchHistoryByUserId(searchHistoryDto);
    }
}
